package com.ims.DAO;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

import com.ims.hibernate.Products;
import com.ims.util.HibernateUtil;



public class ProductsDAO {
	public static void main(String[] args) {
		ProductsDAO productDAO = new ProductsDAO();
		
//	Long a =productDAO.saveproduct(0, "", 1, customInfo, dateCreated, dateTime, height, instock, isCustom, isDeleted, isFeatured, isPublished, isValid, listPrice, manufacturerId, mfrPart, productDesc, productImage, productPrice, productTitle, sKU, supplierCode, supplierId, tax_groupId, taxApplicable, uPCCode, vendorCode, vendType, weight, width)
			//(1 , "abc" , 1 , "abc" , "abc" , "abc" , "abc" , 1 , 1 , 1 , 1 , 1 ,1 , 1.1 , 1 , "abc" ,"abc" , "abc" , 1.1 , "abc" , "abc" , "abc" , 1 , 1 , 1 , "abc" , "abc" , 1 , "abc" , "abc" );
	
	}
	
	public Long saveproduct(long id, String breadth, long categoryId, String customInfo, String dateCreated, String dateTime, String height ,
			long instock, long isCustom, long isDeleted, long isFeatured, long isPublished,long isValid, float listPrice, long manufacturerId, 
			String mfrPart, String productDesc, String productImage, float productPrice, String productTitle, String sKU, String supplierCode, long supplierId,
			long tax_groupId, long taxApplicable, String uPCCode, String vendorCode, long vendType, String weight, String width)
	{
		Session session = HibernateUtil.getSessionFactory().openSession();
		Transaction transaction = null;
		Long p = null;
		
		try {
			transaction = session.beginTransaction();
			Products products = new Products();
			
			
			products.setId(id);
			products.setBreadth(breadth);
			products.setCategoryId(categoryId);
			products.setCustomInfo(customInfo);
			products.setDateCreated(dateCreated);
			products.setDateTime(dateTime);
			products.setHeight(height);
			products.setInstock(instock);
			products.setIsCustom(isCustom);
			products.setIsDeleted(isDeleted);
			products.setIsFeatured(isFeatured);
			products.setIsPublished(isPublished);
			products.setIsValid(isValid);
			products.setListPrice(listPrice);
			products.setManufacturerId(manufacturerId);
			products.setMfrPart(mfrPart);
			products.setProductDesc(productDesc);
			products.setProductImage(productImage);
			products.setProductPrice(productPrice);
			products.setProductTitle(productTitle);
			products.setSKU(sKU);
			products.setSupplierCode(supplierCode);
			products.setSupplierId(supplierId);
			products.setTax_groupId(tax_groupId);
			products.setTaxApplicable(taxApplicable);
			products.setUPCCode(uPCCode);
			products.setVendorCode(vendorCode);
			products.setVendType(vendType);
			products.setWeight(weight);
			products.setWidth(width);
			
			
			session.save(products);
			transaction.commit();
		} catch (HibernateException e) {
			transaction.rollback();
			e.printStackTrace();
		} finally {
			session.close();
		}
		return p;
	}
	


}
